package com.study.spaoplog;

import com.study.spaoplog.base.ShutDownHook;
import com.study.spaoplog.controller.HelloController;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.EnableAspectJAutoProxy;

/**
 * AOP原理【给容器中注册了什么组件，这个组件什么时候工作，这个组件工作时候功能是什么】
 * AspectJAutoProxyRegistrar.class
 * 给容器注入 AnnotationAwareAspectJAutoProxyCreator：
 * 继承 AspectJAwareAdvisorAutoProxyCreator
 * ->AbstractAdvisorAutoProxyCreator
 * -->AbstractAutoProxyCreator
 * --->ProxyProcessorSupport implements SmartInstantiationAwareBeanPostProcessor(bean的后置处理器), BeanFactoryAware
 * ----> 后置处理器：bean初始化前后完成的事情，自动装配 BeanFactoryAware
 * <p>
 * ---后置处理器
 * AbstractAutoProxyCreator.setBeanFactory()
 */
@SpringBootApplication
@EnableAspectJAutoProxy(exposeProxy = true)
public class SpaoplogApplication {
    public static void main(String[] args) {
        //Ctrl +c 先关闭 ffmpeg进程
        // Runtime.getRuntime().addShutdownHook(/*new Thread(CommandManagerUtils::stopAllffmpeg)*/);
        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
            System.out.println(StringUtils.center("Runtime.getRuntime().addShutdownHook", 51, "*"));
        }));
        final ConfigurableApplicationContext applicationContext = SpringApplication.run(SpaoplogApplication.class, args);
        Runtime.getRuntime().addShutdownHook(new ShutDownHook(applicationContext));
        final HelloController bean = applicationContext.getBean(HelloController.class);

    }
}
